/*
 * =====================================================================================
 *
 *       Filename:  cl_time.cxx
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  10/09/2010 10:53:56 AM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Ken Chen (Ziliang), zlchen.ken@gmail.com
 *        Company:  EMC
 *
 * =====================================================================================
 */

#include <sys/times.h>
#include <sys/time.h>
#include <unistd.h>
#include "cl_time.hxx"

namespace neo
{

namespace
{
  const int CL_TICKS_PER_SECOND = 100;
}

long CLTime::ticksPerSecond(void)
{
  long ticks = sysconf(_SC_CLK_TCK);
  if(ticks > 0)
  {
    return ticks;
  }
  else
  {
    return CL_TICKS_PER_SECOND;
  }
}

unsigned long CLTime::ticksForUSec(unsigned long uSec)
{
	double seconds = (uSec*1.0)/1000000;
	return static_cast<unsigned long>(seconds*ticksPerSecond());
}

} // neo
